<?php
function http_post_data($url, $data_string) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSLVERSION, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json; charset=utf-8',
        'Content-Length: ' . strlen($data_string))
    );
    ob_start();
    curl_exec($ch);
    $return_content = ob_get_contents();
    //echo $return_content."<br>";
    ob_end_clean();
    $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    // return array($return_code, $return_content);
    return $return_content;
}

$url = "https://qr-test2.chinaums.com/netpay-route-server/api/"; 

 /*************/
 
$mdKey='fcAmtnx7MwismjWNhNKdHC44mNXtnEQeJkRrhKJwyrW2ysRR';
$time=time();
$requestTimestamp=date('Y-m-d H:i:s', $time);
//$merOrderId=date('YmdHis').mt_rand(100000, 999999);
$merOrderId='319420200226153000001';//要查询的订单号
$mid='898340149000005';
$tid='00000001';

	
$data=[
    'msgId'=>'msgIdQuery',
    'msgSrc'=>'WWW.TEST.COM',
    'msgType'=>'query',
    'requestTimestamp'=>$requestTimestamp,
    'srcReserve'=>'srcReserveQuery',
    'mid'=>$mid,
    'tid'=>$tid,
    'instMid'=>'YUEDANDEFAULT', //H5DEFAULT 两种都可以。。
    'merOrderId'=>$merOrderId,
    'signType'=>'MD5'];	 
	 
	 ksort($data);
	 reset($data);
	 $options='';
	 foreach ($data as $key=>$value) {
		 $options.=$key.'='.$value.'&';
	 }
	 $options=rtrim($options, '&');
	 //存在转义字符，那么去掉转义
	 if (get_magic_quotes_gpc()) {
		 $options=stripslashes($options);
	 }
	 
	 echo "<pre>";
	 print_r($data);
	 echo "<pre>";
	 echo "<br>";
	 $sign=strtoupper(md5($options.$mdKey));
    $data['sign'] = $sign;
	 echo '上面生成的sign:'.$sign;
	 //$sign='3A7E1F723C9E7D210C2A1C1DD5120099';
	 $options.='&sign='.$sign;
	 
 
 /***************/
  

//list($return_code, $return_content) = http_post_data($url, $data); 
$aaa = http_post_data($url, json_encode($data));

echo "<br><br>返回值 ：";
//var_dump($aaa);  
print_r(json_decode($aaa)); 
?>